@extends("layout.admin")

@section("title")
    用户列表
@endsection

@section("content")
    {{--修改样式--}}
    <style>
        .layui-input {
            width: 60% !important;
        }

        .layui-edge {
            right: 161px !important;
        }

        .layui-form-select dl {
            min-width: 60% !important;
        }

        .layui-form-label {
            width: 134px !important;
        }

        .layui-input-block {
            margin-left: 164px !important;
        }
    </style>
    {{--添加--}}
    <form id="create_from" style="display: none;margin-top: 15px;" class="layui-form" action="{{route('admin.user.store')}}" method="post">
        {{csrf_field()}}
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-block">
                <input type="text" id="name" name="name" autocomplete="off" placeholder="账号" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="email" id="email" name="email" autocomplete="off" placeholder="邮箱" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="password" id="password" name="password" autocomplete="off" placeholder="密码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">重复密码</label>
            <div class="layui-input-block">
                <input type="password" id="password_confirmation" name="password_confirmation" autocomplete="off" placeholder="重复密码" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="reset" class="layui-btn layui-btn-normal">重置</button>
                <button type="submit" class="layui-btn">立即提交</button>
            </div>
        </div>
    </form>

    <div class="layui-card-body ">
        <form class="layui-form layui-col-space5">
            <div class="layui-inline layui-show-xs-block">
                <a class="layui-btn" data-method="create" data-type="auto" id="create"><i class="layui-icon"></i>添加</a>
            </div>
        </form>
    </div>

    {{--列表--}}
    <div class="layui-card-body ">
        <form class="layui-form layui-col-space5" id="search-form">
            <div class="layui-inline layui-show-xs-block">
                <input type="text" name="name"  placeholder="请输名称" value="{{ request("name") }}" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-inline layui-show-xs-block" style="margin-left: -80px;">
                <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
            </div>
        </form>
    </div>
    <div class="layui-card-body ">
{{--        <table  lay-filter="table-hide" style="display: none" lay-data="{height:'full-310', cellMinWidth: 80,toolbar: '#toolbar', limit: {{ $adminUsers->perPage() }} }">--}}
        <table  lay-filter="table-hide" style="display: none">
            <thead>
            <tr>
                <th lay-data="{field:'id',width:80, fixed: 'left', unresize: true, sort: true}">编号</th>
                <th lay-data="{field:'name'}">名称</th>
                <th lay-data="{field:'email'}">邮箱</th>
                <th lay-data="{field:'mobile'}">电话</th>
{{--                <th lay-data="{field:'status'}">状态</th>--}}
                <th lay-data="{field:'created_at'}">创建时间</th>
                <th lay-data="{field:'updated_at'}">更新时间</th>
                <th lay-data="{field:'op',fixed: 'right', width:200, align:'center'}">操作</th>
            </tr>
            </thead>
            <tbody>
            @foreach ($user as $u)
                <tr>
                    <td>{{ $u->id }}</td>
                    <td>{{ $u->name }}</td>
                    <td>{{ $u->email }}</td>
                    <td>{{ $u->mobile }}</td>
                    <td>{{ $u->created_at }}</td>
                    <td>{{ $u->updated_at }}</td>
                    <td>
                        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                        <a class="layui-btn layui-btn-xs" href="{{ route("admin.user.edit", ['id' => $u->id]) }}">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="del('/admin/user/destroy', {{$u->id}}, '{{route('admin.user.index')}}', '你确定要删除这个用户吗？')">删除</a>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>

        <div style="float: right;">{{ $user->links() }}</div>


    </div>
@endsection

@section('script')
    <script>
        layui.use(['form', 'table'], function () {
            var table = layui.table;
            var form = layui.form;
            table.init("table-hide");

            //触发事件
            var active = {
                /*添加账号*/
                create: function (othis) {
                    var type = othis.data('type');
                    console.log(type);
                    layer.open({
                        title: "添加账号",
                        area: ["500px", "335px"]
                        , type: 1
                        , offset: type
                        , id: 'create'+type //防止重复弹出
                        , content: $("#create_from")
                        , btnAlign: 'c' //按钮居中
                        , shade: 0 //不显示遮罩
                        , success: function () {
                            form.render();
                        }
                    });
                }
            };

            $('#create').on('click', function () {
                var othis = $(this), method = othis.data('method');
                active[method] ? active[method].call(this, othis) : '';
            });
        });
    </script>
    <script src="{{asset('js/layCommon.js')}}"></script>
@endsection
